height = [1, 8, 6, 2, 5, 4, 8, 3, 7]

i = 0
j = len(height) - 1
width = len(height) - 1
area = 0
while (i <= j):
    if height[i] <= height[j]:
        if area < (j - i) * height[i]:
            area = (j - i) * height[i]
    if height[i] > height[j]:
        if area < (j - i) * height[j]:
            area = (j - i) * height[j]
    if height[i] < height[j]:
        i = i + 1
    else:
        j = j - 1

print(area)
